﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.Linq;
using Security;
using Stats;
using Stats.Objects;
using Storage;
using System.Xml;


namespace Groupware
{
    public class UserManager
    {
        #region Methods

        /// <summary>
        /// This method is called from GUI to retrieve the last 5 registered users. It calls StatsModule.
        /// </summary>
        /// <returns>list of registeredUser objects. Each object contains username and userID</returns>
        public static List<RegisteredUser> getLastFiveRegisteredUsers()
        {
            return StatsModule.getLastNRegisteredUsers(5);
        }
        
        /// <summary>
        /// This method is called from GUI to retrieve the total count of registered users (with bookedIn == true). It calls StatsModule.
        /// </summary>
        /// <returns>int - registered users count</returns>
        public static int getTotalRegisteredUsersCount()
        {
            return StatsModule.getRegisteredUsersCount();
        }
        

        /// <summary>
        /// This method is called from GUI to discover if there are pending feedbacks to left for that user. It calls StatsModule.
        /// </summary>
        /// <returns>int. Count of pending feedbacks..  0 = NO PENDING FEEDBACKS</returns>
        public static int hasPendingFeedbacksToLeft(int userID)
        {
            return StatsModule.hasPendingFeedbacks(userID);
        }
        

        /// <summary>
        /// This method is called from GUI to retrieve the user list of trips which he has to left one or more feedbacks. It calls StatsModule.
        /// </summary>
        /// <returns>list of TripProperties objects. Each object contains trip infos</returns>
        public static List<TripProperties> getUserTripsWithFeedbacksToLeft(int userID)
        {
            return StatsModule.getUserTripsWithPendingFeedbacks(userID);
        }


        /// <summary>
        /// This method is called from GUI to retrieve the user feedbacks to left for that trip. It calls Stats Module.
        /// </summary>
        /// <param name="loggedUserID">Logged user ID</param>
        /// <param name="tripID">TripID</param>
        /// <returns>A list of feedback requests that the user has to left for other users</returns>
        public static List<FeedbackRequest> getPendingFeedbacksForTripToLeft(int loggedUserID, int tripID)
        {
            return StatsModule.getPendingFeedbacksForTrip(loggedUserID, tripID);
        }

         //DEPRECATED
        /// <summary>
        /// This method is called from GUI when user home page is open to retrieve the user feedbacks to left. It calls Stats Module.
        /// </summary>
        /// <param name="loggedUserID">Logged user ID</param>
        /// <returns>A list of feedback requests that the user has to left for other users</returns>
        //public static List<FeedbackRequest> getPendingFeedbacksToLeft(int loggedUserID)
        //{
        //    return StatsModule.getPendingFeedbacks(loggedUserID);
        //}

        /// <summary>
        /// This method is called from GUI when a feedback is released. It calls Stats module.
        /// </summary>
        /// <param name="feedback">RelasedFeedback object</param>
        /// <returns>boolean TRUE = INSERT OK...FALSE = INSERT ERROR</returns>
        public static bool releaseFeedback(ReleasedFeedback feedback)
        {
            return StatsModule.insertReleasedFeedback(feedback);
        }
        


        /// <summary>
        /// this method returns the driver feedback associated to this User object. It calls Stats module.
        /// </summary>
        /// <returns>the driver feedback object to display</returns>
        public static AsDriverFeedback getDriverFeedback(int userID)
        {
            AsDriverFeedback driver_feed = StatsModule.getAsDriverFeedback(userID);
            return driver_feed;
        }

        /// <summary>
        /// this method returns the passenger feedback associated to this User object. It calls Stats module.
        /// </summary>
        /// <returns>the passenger feedback object to display</returns>
        public static AsPassengerFeedback getPassengerFeedback(int userID) 
        {
            AsPassengerFeedback passenger_feed = StatsModule.getAsPassengerFeedback(userID);
            return passenger_feed;            
        }

        /// <summary>
        /// this method returns the general feedback associated to this User object. It calls Stats module.
        /// </summary>
        /// <returns>the general feedback object to display</returns>
        public static GeneralFeedback getUserFeedback(int userID) 
        {
            GeneralFeedback gf = StatsModule.getGeneralFeedback(userID);
            return gf;
        }

        /// <summary>
        /// this method returns complete stats of another user. It calls Stats module.
        /// </summary>
        /// <param name="userID">other user ID</param>
        /// <returns>the general stats object of another user to display</returns>
        public static UserProfile getUserStats(int userID) 
        {
            UserProfile up = StatsModule.getUserProfile(userID);
            return up;
        }

        // DEPRECATED
        /// <summary>
        /// this method returns the TripLOA general statistics to display. It calls Stats module.
        /// </summary>
        /// <returns>the general stats to display</returns>
        //public static GeneralStats getGeneralStats() 
        //{
        //    return StatsModule.getGeneralStats();
        //}

        /// <summary>
        /// this method calls Anonymizer when this user wants to get his own profile.
        /// </summary>
        /// <returns>the user profile object to display</returns>
        public static Profile getUserProfile(int userID) 
        {
            //return (new User(userID)).GetProfile();
            return (TripLoaUserManager.Instance.getUser(Storage.StorageManager.Instance.GetUserById(userID).Username).GetProfile(userID));
        }

        /// <summary>
        /// this method calls Anonymizer when this user wants to get the profile of another user.
        /// </summary>
        /// <param name="userID">other user ID</param>
        /// <returns>the other user profile object to display</returns>
        public static Profile getUserProfile(int userID, int otherUserID)
        {
            //return (new User(userID)).GetProfile(otherUserID);
            return (TripLoaUserManager.Instance.getUser(Storage.StorageManager.Instance.GetUserById(userID).Username).GetProfile(otherUserID));

        }
        
        /// <summary>
        /// Sets the user vehicle type in the user profile. The user car vehicle type is used for stats.
        /// </summary>
        /// <param name="userID">UserID</param>
        /// <param name="vehicleType">Vehicle Type. Use the car types defined in StatsModule</param>
        /// <returns>True = set OK..False = error</returns>
        public static bool setUserVehicleType(int userID, int vehicleType)
        {
            return StatsModule.setUserVehicleType(userID, vehicleType);
        }

        /// <summary>
        /// Gets the user vehicle type in the user profile. The user car vehicle type is used for stats.
        /// </summary>
        /// <param name="userID">UserID</param>
        /// <returns>Returns a car vehicle type as specified in StatsModule</returns>
        public static int getUserVehicleType(int userID)
        {
            return StatsModule.getUserVehicleType(userID);
        }




        /// <summary>
        /// (DEPRECATED: this method is implemented in Anonymizer package)
        /// </summary>
        /// <param name="userID"></param>
        /// <returns></returns>
        public static List<Storage.EntityModels.Users_VehicleDetails> GetVehicles(int userID)
        {
            var uvd = from u_vd in StorageManager.Instance.Entities.Users_VehicleDetails
                      where u_vd.UserId == userID
                      select u_vd;

            return uvd.ToList();
        }
        
        #endregion

        #region Notification

        public static List<Notification> GetNotification(int userID)
        {
            String xmlstring = "";
            //String xmlstring = Storage....DB.GET();
            XmlDocument xmldocument = new XmlDocument();
            xmldocument.LoadXml(xmlstring);
            return new List<Notification>();
        }
        
        #endregion
    }
}
